<template>
    <div>
      <el-header class="classheader" v-if="windows === 0">
    <span >添加专业</span>
</el-header>
      <van-form @submit="onSubmit(major_name, major_id), CreateClass()">
    <van-field
      v-model="major_name"
      name="班级名"
      label="班级名"
      placeholder="请填写专业名"
      :rules="[{ required: true, }]"
    />
    <van-field
      v-model="major_id"
      type="textarea"
      name="专业编号"
      label="专业编号"
      placeholder="请填写专业编号"
      :rules="[{ required: true,  }]"
    />
    <div style="margin: 16px;" >
      <van-button round block type="info" native-type="submit" >添加专业</van-button>
    </div>
  </van-form>
    </div>
  </template>
  
  <script>
  import axios from 'axios';
  export default {
      name: 'addMajor',
      data() {
      return {
        windows:0,
        major_id: '',
        major_name: '',
      };
    },
    mounted(){
      if (window.innerWidth < 768) {
        this.windows = 1;
      } else {
        this.windows = 0;
      }
    },
      methods: {
      onSubmit(major_name, major_id) {
        console.log(major_id, major_name);
        axios.post('/class/addMajor?major_id=' + major_id + '&major_name=' + major_name).then(response => {
          console.log(response);
          this.$router.push('/Class'); 
        }).catch(error => {
        //   console.log(error);
          this.$message.error('添加失败，请检查是否已有该专业');
        });
      },
    //   CreateClass() {  
    //     // console.log("提交！");
    //     // this.$router.push('/Class');  
    //   },
    },
  }
  </script>
  
  <style scoped> 
    .classheader {
    background-color: #424242;
  }
  .classheader span {
    /* height: 60px;
    width: 300px;
    background-color: #f42525; */
    color: #fff;
    font-size: 20px;
    text-align: center;
    line-height: 60px;
  }
  </style>